package com.css.fxfzmh.base.dict;

import cn.afterturn.easypoi.excel.entity.result.ExcelVerifyHandlerResult;
import cn.afterturn.easypoi.handler.inter.IExcelVerifyHandler;
import com.css.fxfzmh.base.dict.repository.entity.DictEntity;
import com.css.fxfzmh.base.dict.service.DictService;
import com.css.fxfzmh.base.dict.viewobjects.DictExcelVO;
import com.css.fxfzmh.util.PlatformObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author chenjun
 * @Date 2020/4/26
 * @Description
 */

@Component
public class DictExcelVerifyHandler implements IExcelVerifyHandler<DictExcelVO> {

    @Autowired
    DictService dictService;

    @Override
    public ExcelVerifyHandlerResult verifyHandler(DictExcelVO dictExcelVo) {
        ExcelVerifyHandlerResult result = new ExcelVerifyHandlerResult(true);
        StringBuffer message = new StringBuffer("");
        DictEntity dictEntity = dictService.getDict(dictExcelVo.getDictId());
        if(!PlatformObjectUtils.isEmpty(dictEntity)){
            result.setSuccess(false);
            message.append("字典"+dictEntity.getDictName()+"已存在");
        }
        result.setMsg(message.toString());
        return result;
    }
}
